<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\AuthController;
use Think\Auth;

class GlobalController extends AuthController {
	
    public function setjifen(){
    	 if (!IS_AJAX)
        {
            $jifen=M('jifen')->where(array('jifen_id'=>1))->find();
            $this->assign('jifen',$jifen)->display();
        }
        else
        {   $_POST['fh_open']=$_POST['fh_open']?$_POST['fh_open']:0;
            M('jifen')->save($_POST);
            $this->success('积分设置成功',1,1);
        }
		$this->display();
    }

    public function fund(){

         if (!IS_AJAX)
        {
            $sys=M('sys')->where(array('sys_id'=>1))->find();
            $this->assign('sys',$sys)->display();
        }
        else
        {    
            M('sys')->save($_POST);
            $this->success('公益基金设置成功',1,1);
        }
        $this->display();
    }

    public function setmoshi()
    {  
        
        $moshi=M('moshi')->select();
        $this->assign('moshi',$moshi);
        $this->display();
    }

     public function moshi_add()
    {

        if (!IS_AJAX)
        {
            $this->display();
        }
        else
        {   
            $sldata=$_POST;
            $sldata['settime']=time();
            $sldata['totaljifen']=$_POST['moshi_cf_jifen']*($_POST['moshi_week1_num']+$_POST['moshi_week2_num']);
            M('moshi')->add($sldata);
            $this->success('模式添加成功',U('setmoshi'),1);
        }
    }

    public function moshi_edit()
    {
            if (!IS_AJAX)
        {   
            $moshi=M('moshi')->where(array('moshi_id'=>I('id')))->find();
            $this->assign('moshi',$moshi);
            $this->display();      
        }
        else
        {   $_POST['status']=$_POST['status']?$_POST['status']:0;
            M('moshi')->save($_POST);
            $this->success('模式修改成功',U('setmoshi'),1);
        }
    }

    public function moshi_state()
    {
        $id=I('x');
        $status=M('moshi')->where(array('moshi_id'=>$id))->getField('status');//判断当前状态情况
       
$count=M('moshi')->where('status=1')->count();
        if($status==1)
        {
            $statedata = array('status'=>0);
            $moshi=M('moshi')->where(array('moshi_id'=>$id))->setField($statedata);
            $this->success('状态禁止',1,1);
        }
        else
        {

        if ($count>=1) {
           $this->error('只能开启一个模式');
        }else{
          $statedata = array('status'=>1);
            $moshi=M('moshi')->where(array('moshi_id'=>$id))->setField($statedata);
            $this->success('状态开启',1,1);  
        }

            
        }
    }


    public function setjibie()
    {   
         if (!IS_AJAX)
        {   

            $jibie=M('jbset')->find();
            $this->assign('jibie',$jibie);
            $this->display();
        }
        else
        {   
            $sldata=$_POST;
            $sldata['settime']=time();
            M('jbset')->save($sldata);
            $this->success('级别设置成功',U('setjibie'),1);
        }


    }
}